package router

import (
	"oa-system/internal/api/handler"
	"oa-system/internal/api/middleware"
	"oa-system/internal/config"
	"oa-system/internal/database"
	"oa-system/internal/repository"
	"oa-system/internal/service"

	"github.com/gin-gonic/gin"
)

func RegisterRoleRoutes(r *gin.Engine) {
	// 创建存储库、服务和控制器
	roleRepo := repository.NewRoleRepository(database.DB)
	roleService := service.NewRoleService(roleRepo)
	roleHandler := handler.NewRoleHandler(roleService)

	api := r.Group(config.GlobalConfig.App.APIPrefix)

	// 需要认证的路由
	roleGroup := api.Group("/roles")
	roleGroup.Use(middleware.JWTAuthMiddleware())
	{
		roleGroup.POST("/assignMenus", roleHandler.AssignMenus)
		roleGroup.POST("/", roleHandler.CreateRole)
		roleGroup.GET("/", roleHandler.GetAllRoles)
		roleGroup.GET("/:id", roleHandler.GetRoleByID)
		roleGroup.PUT("/:id", roleHandler.UpdateRole)
		roleGroup.DELETE("/:id", roleHandler.DeleteRole)
		roleGroup.GET("/:id/assignedMenus", roleHandler.GetAssignedMenus)
	}
}
